import requests
class YunPian:
    def send_single_sms(self, code, mobile):
        headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
        api_id = "C58308587"
        api_key = "8d36459b182b9974882a341b86616bb9"
        url = "http://106.ihuyi.cn/webservice/sms.php?method=Submit&account={}&password={}&mobile={}"
        text = "您的验证码是：{}。请不要把验证码泄露给其他人。".format(code)
        data = {
            'account': api_id,
            'password': api_key,
            'content': text,
            'mobile': mobile,
            'format': 'json'
        }

        response = requests.post(url, headers=headers, data=data)
        return response


        # url = "https://sms.yunpian.com/v2/sms/single_send.json"
        # api_key = "f862c51c7543d3995678ac784574636a"
        # data = {
        #     "apikey": api_key,
        #     "mobile": mobile,
        #     "text": "【云片网】您的验证码是{}".format(code)
        # }
        # response = requests.post(url, data=data)
        # return response

if __name__ == '__main__':
    yun = YunPian()
    res = yun.send_single_sms("1234", "17607560047")
    print(res.text)